﻿using ApiManage.Models.MongoMappings.Sys;
using ApiManage.Service.MySql.Sys;
using ApiManage.Svc.Filter;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Driver;
using Rhonin.Common.Entity.Api;
using Rhonin.Common.Entity.Page;
using System;
using System.Linq;
using System.Linq.Expressions;

namespace ApiManage.Svc.Controllers.System
{
    /// <summary>
    /// 用户接口
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class SysUserControllerMysql : BaseController
    {
        private readonly ISysUserQueryService _sysUserQueryService;
        /// <summary>
        /// 
        /// </summary>
        public SysUserControllerMysql(ISysUserQueryService sysUserQueryService)
        {
            _sysUserQueryService = sysUserQueryService;
        }

        /// <summary>
        /// 分页获取管理用户
        /// </summary>
        /// <param name="name"></param>
        /// <param name="roleId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [Route("GetUser"), HttpGet,CheckLogin]
        public ApiResult<PageResult<SysUser>> GetUser(string name, string roleId, int pageIndex, int pageSize)
        {
            var param = new QueryPage
            {
                PageIndex = pageIndex,
                PageSize = pageSize
            };
            Expression<Func<SysUser, bool>> where = o => o.Mark != 9;
            var list = _sysUserQueryService.GetList(param);
            var result = new PageResult<SysUser>
            {
                TotalCount = list.Count,
                Items = list.OrderByDescending(o => o.CreateTime).Skip(param.Skip).Take(param.Limit),
                PageParameter = param
            };
            return CreateResult(result);
        }
    }
}